//@author A0081058H
package net.mysoc.w111j.util;

import java.util.HashMap;

import javafx.scene.control.Separator;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.paint.Color;

/**
 * This class contains utility methods for UI layout.
 */
public class Layout {
    /**
     * Creates and returns a {@code Separator} which floats all elements after it to the right.
     *
     * @return a {@code Separator} which floats all elements after it to the right.
     */
    public static Separator hboxFloatRight() {
        Separator separator = new Separator();
        separator.setStyle("-fx-opacity: 0");
        HBox.setHgrow(separator, Priority.ALWAYS);

        return separator;
    }

    /**
     * Converts a {@code String} to a {@code HashMap} with hue, saturation and lightness as keys.
     *
     * @param input {@code String} to convert.
     * @return a {@code HashMap} with hue, saturation and lightness as keys.
     */
    public static HashMap<String, String> stringToHsl(String input) {
        // Hue: 0-360
        // Saturation: 0-100%
        // Lightness: 0-100%

        HashMap<String, String> hsl = new HashMap<>();
        Double hash = Math.pow(input.hashCode(), 2); // A more "random" value
        int hue = (int) (hash % 360);

        hsl.put("hue", Integer.toString(hue));
        hsl.put("saturation", "80%");
        hsl.put("lightness", "80%");

        return hsl;
    }

    /**
     * Converts a {@code String} to a formatted CSS colour {@code String}.
     *
     * @param input {@code String} to convert.
     * @return a {@code String} to a formatted CSS colour {@code String}.
     */
    public static Color stringToHslColor(String input) {
        HashMap<String, String> hsl = Layout.stringToHsl(input);
        String h = hsl.get("hue");
        String s = hsl.get("saturation");
        String l = hsl.get("lightness");
        return Color.web("hsl(" + h + "," + s + "," + l + ")");
    }
}
